package com.hp.attendance.serlvet.attendanceManager;

import com.hp.attendance.entity.Overtime;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/updateOver")
public class updateOvertimeServlet extends HttpServlet {

    private OvertimeService overtimeService=new OvertimeService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        String department_number = req.getParameter("departmentNumber");
        String employee_number = req.getParameter("employeeNumber");
        String date = req.getParameter("date");
        Overtime overtime = new Overtime();
        overtime.setDay(date);
        overtime.setEmployee_number(Integer.valueOf(employee_number));
        overtime.setDepartment_number(Integer.valueOf(department_number));
        overtime.setId(Integer.valueOf(id));
        try {
            overtimeService.updateOvertime(overtime);
            req.getRequestDispatcher("/overtimeMange?pageNo=1").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
